using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Microsoft.EntityFrameworkCore.Dm.Metadata.Internal;

public class DmAnnotationProvider : RelationalAnnotationProvider
{
	public DmAnnotationProvider([NotNull] RelationalAnnotationProviderDependencies dependencies)
		: base(dependencies)
	{
	}

	public override IEnumerable<IAnnotation> For(IColumn column, bool designTime)
	{
		StoreObjectIdentifier table = StoreObjectIdentifier.Table(((ITableBase)column.Table).Name, ((ITableBase)column.Table).Schema);
		IProperty val = column.PropertyMappings.Select((IColumnMapping m) => ((IColumnMappingBase)m).Property).FirstOrDefault((Func<IProperty, bool>)((IProperty p) => ((IReadOnlyProperty)(object)p).GetValueGenerationStrategy(in table) == DmValueGenerationStrategy.IdentityColumn));
		if (val != null)
		{
			int? identitySeed = ((IReadOnlyProperty)(object)val).GetIdentitySeed();
			int? identityIncrement = ((IReadOnlyProperty)(object)val).GetIdentityIncrement();
			yield return (IAnnotation)new Annotation("Dm:Identity", (object)string.Format(CultureInfo.InvariantCulture, "{0}, {1}", identitySeed.GetValueOrDefault(1), identityIncrement.GetValueOrDefault(1)));
		}
	}
}
